require "sequel"

DB = Sequel.sqlite('tcconline.db')

class Usuario < Sequel::Model
plugin :schema

set_schema do
  primary_key :id
  string :usuario, :null => false
  string :senha, :null => false
  string :email, :null => false
  integer :professor_id
  boolean :esta_ativo
  boolean :admin
end


  unless table_exists?
    create_table
	create :usuario => 'admin', :senha => 'admin', :email => 'admin@admin.com', :esta_ativo => true, :admin => true
	create :usuario => 'Daniel', :senha => 'daniel', :email => 'daniel@daniel.com', :esta_ativo => true, :admin => true
	create :usuario => 'Vinicius', :senha => 'vinicius', :email => 'vinicius@vinicius.com', :esta_ativo => true, :admin => true
	create :usuario => 'Guilherme', :senha => 'guilherme', :email => 'guilherme@guilherme.com', :esta_ativo => true, :admin => true
	create :usuario => 'aluno', :senha => 'aluno', :email => 'aluno@aluno.com', :professor_id => 1, :esta_ativo => true, :admin => false
  end
  
  def ativar
    @esta_ativo = true
  end
  
  def self.todos_admins
	filter :admin => true, :esta_ativo => true
  end
  
  def self.todos_alunos_de(id)
	filter :professor_id => id
  end
end


class Avaliacao < Sequel::Model
  plugin :schema
  
  set_schema do
    primary_key :id
    string :avaliacao
    string :av_professor
    integer :usuario_id
    integer :professor_id
  end
  
   unless table_exists?
	create_table
   end
#teste
  def self.avalia
	filter :id 
  end
end


class Agenda < Sequel::Model
  plugin :schema
  
  set_schema do
    primary_key :id
    string :evento
    string :data
    string :local
    string :inf
    string :professor
    integer :professor_id
    end
          
   unless table_exists?
	create_table
   end

  def self.mostra_agenda
	filter :id
  end
end